package com.maolong.controller.item;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.maolong.entity.domain.Item;
import com.maolong.entity.domain.Order;
import com.maolong.entity.domain.Shop;
import com.maolong.entity.domain.User;
import com.maolong.entity.format.Code;
import com.maolong.entity.format.RespResult;
import com.maolong.service.IItemService;
import com.maolong.service.IOrderService;
import com.maolong.service.LoginService;
import com.maolong.service.impl.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@Slf4j
public class ShopController {
    @Autowired
    ShopService shopService;
    @Autowired
    LoginService loginService;
    @Autowired
    IItemService iItemService;
    @Autowired
    IOrderService iOrderService;
    private String username;


    /**
     * 用来购买特定商品，插入数据库表
     * @param shop
     * @return
     */
    @PostMapping("/shop")
    @ResponseBody
    public RespResult shopItem(@RequestBody Shop shop){
        log.info("shop:{}",shop);
        System.out.println(shop);
        boolean save = shopService.save(shop);
        return new RespResult(Code.ORDER_OK, save,"购买成功");
    }

    @GetMapping("/shop")
    @ResponseBody
    public RespResult shopItem(@RequestParam(value = "id") Long id){
        log.info("id:{}",id);
        List orderList = iOrderService.getOrder(id);
        System.out.println(orderList);
        return new RespResult(Code.USER_OK,orderList,"展示成功");
    }
}
